/********************************************************************
	Rhapsody	: 7.5 
	Login		: kbe
	Component	: DefaultComponent 
	Configuration 	: CodeConfig
	Model Element	: AlarmEvent
//!	Generated Date	: Thu, 27, Sep 2012  
	File Path	: DefaultComponent\CodeConfig\AlarmEvent.cpp
*********************************************************************/

//## auto_generated
#include "AlarmEvent.h"
//## auto_generated
#include "Reactor.h"
//## package Default

//## class AlarmEvent
AlarmEvent::AlarmEvent() {
}

AlarmEvent::AlarmEvent(Reactor * reactor, SOCK_Stream * stream) {
    //#[ operation AlarmEvent(Reactor *,SOCK_Stream *)
    //#[ operation LogEvent(Reactor*,SOCK_Stream)
    setPeer_stream_(stream);
    handle = (HANDLE)stream->get_handle();
    type = READ_EVENT;
    itsReactor = reactor;
    //#]
}

AlarmEvent::~AlarmEvent() {
}

int AlarmEvent::handleEvent(HANDLE h, Event_Type& et) {
    //#[ operation handleEvent(HANDLE,Event_Type)
    if (et == type) {
    	int n = getPeer_stream_()->recv_n(buffer_, sizeof(buffer_), 0);
    	if (n > 0) { 
    		AlarmAction();
    	}
    	else 
    	{
    		delete this; // Deallocate ourselves
    		return -1;
    	}
    }
    return 0;
    //#]
}

void AlarmEvent::AlarmAction() {
    //#[ operation AlarmAction()
    char temp[2*SIZE_BIG];
    printf("AlarmEvent: %s\n", buffer_);
    sprintf(temp, "Server: %s\n", buffer_);
    getPeer_stream_()->send_n(temp, strlen(temp)+1, 0);
    //#]
}

char AlarmEvent::getBuffer_(int i1) const {
    return buffer_[i1];
}

void AlarmEvent::setBuffer_(int i1, char p_buffer_) {
    buffer_[i1] = p_buffer_;
}

/*********************************************************************
	File Path	: DefaultComponent\CodeConfig\AlarmEvent.cpp
*********************************************************************/
